<?php
$libdir = dirname(__FILE__);
require_once "{$libdir}/coreLib.php";
require_once "{$libdir}/Element.php";
/**
 * The element with some specific Web 2.0 stuff
 *
 * @author cornel
 */
class WebElement extends Element {
    private $clases = array();  // Element classes (primarely for CSS)
    private $css = array();  // CSS style
    public function  __construct() {
        parent::__construct();
        
    }

    /**
     * Register a new class for the element
     * @param string $className the name for the new class
     */
    public function addClass($className) {
        $className = trim($className);
        if(preg_match("/^[_a-zA-Z]+[_a-zA-Z0-9-]*$/i",$className))
        if(array_search($className, $this->clases) === FALSE)
            $this->clases[]= $className;
    }

    /**
     *  Remove the named class from the list
     * @param <type> $className
     */
    public function removeClass($className)
    {
        $key = array_search($className, $this->clases);
        if($key !== FALSE)
        {
            unset($this->clases[$key]);
        }
    }

    
    /**
     * Transform the Web Element to HTML code
     * @param bool $echo Display the content or not
     * @return string 
     */
    public function  toHtml($echo = true) {
        $this->setAttribute('class', implode($this->clases,' '));
        $this->setAttribute('id', $this->getID());
        return parent::toHtml($echo);
    }
}
?>
